home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- *
- * Apple Macintosh Developer Technical Support
- *
- * Installer 3.1 sample: User Functions
- *
- * File: UserFunction.c - c Source
- *
- * by: Jon Zap
- * updated for use with Installer 3.4 by: Rich Kubota 9/1/92
- *
- * Copyright © 1988-1990 Apple Computer, Inc.
- * All rights reserved.
- *
- *----------------------------------------------------------------------------*/
- #if 0
- c -b UserFunction.c
- Link -ra =resPurgeable -rt infn=1001 -rn -m USERFUNCTION -t rsrc -c RSED ∂
- UserFunction.c.o ∂
- "{Libraries}"Interface.o ∂
- -o UserFunction.rsrc
- #endif
-
- /* applec is only defined by MPW C so we can use it to make versions that work
- with MPW C and THINK C
- */
- #ifdef applec
- #include <CType.h>
- #include <Quickdraw.h>
- #include <Windows.h>
- #include <OSUtils.h>
- #include <desk.h>
- #include <dialogs.h>
- #include <Errors.h>
- #include <Events.h>
- #include <Memory.h>
- #include <Menus.h>
- #include <SegLoad.h>
- #include <Slots.h>
- #include <ToolUtils.h>
- #include <Devices.h>
- #include <Resources.h>
- #include <SysEqu.h>
- #endif
-
- #include "UserFunction.h"
-
- #ifndef applec
- #define screenActive scrnActive
- #endif
-
- #define kTobyBoardID 5
-
- Boolean checkBoardID(void);
-
- pascal Boolean UserFunction(short targetVRefNum, long blessedID, long whichFunction)
- {
- #pragma unused (blessedID, targetVRefNum)
-
- switch (whichFunction) { /* switch is useless here but we assume that we'll add other userFunctions */
-
- case FindMyBoard:
- return checkBoardID();
- }
- }
-
- Boolean checkBoardID()
- {
- int Index,i;
- OSErr err;
- int slots[6];
- GDHandle aDev, aDevList[6];
- AuxDCEHandle DCE;
- int lastDevIndex;
- SInfoRecord mySInfoRec;
- SpBlock mySpBlock;
- SysEnvRec theSys;
- short theBoardID;
-
-
- err = SysEnvirons(1,&theSys); /* should use gestalt (or even better check with a rule before calling this function) */
- if (err!=noErr || !theSys.hasColorQD) { /* without color QD this thing is irrel */
- return false;
- }
-
- /* go thru the graphics device list and get the list of active screen gdevices
- and the slot numbers of their cards
- */
- for (Index = 0, aDev = GetDeviceList(); aDev; aDev = GetNextDevice(aDev))
- if (TestDeviceAttribute(aDev,screenDevice)&&TestDeviceAttribute(aDev,screenActive))
- {
- aDevList[Index] = aDev;
- lastDevIndex = Index;
- DCE = (AuxDCEHandle) GetDCtlEntry((**aDev).gdRefNum);
- slots[Index] = (**DCE).dCtlSlot; /* get the slot number */
- Index++;
- }
-
- /* go thru each of the devices/cards and see if the board id is MINE */
- for (i=0; i<=lastDevIndex; i++) {
- Index = slots[i];
- /* init parameters for SReadInfo */
- mySpBlock.spResult = (long) &mySInfoRec;
- mySpBlock.spSlot = Index; /* which slot to look at */
-
- /* let's see if any board is in the slot */
- err = SReadInfo (&mySpBlock);
- if (err) {
- /* report error */
- continue;
- }
-
- if (mySInfoRec.siInitStatusA == smEmptySlot) { /* pretty weird if no card! */
- continue;
- }
-
- /* init parameters for sNextTypesRsrc, look for card info of the following type */
- /* Look in slot (Index) */
- mySpBlock.spSlot = Index;
- mySpBlock.spID = 0;
- mySpBlock.spExtDev = 0;
- mySpBlock.spCategory = 1;
- mySpBlock.spCType = 0;
- mySpBlock.spDrvrSW = 0;
- mySpBlock.spDrvrHW = 0;
-
- err = SNextTypeSRsrc (&mySpBlock);
-
- if (err) { /* report error */
- continue;
- }
-
- /* init parameters for SReadWord */
- mySpBlock.spID = 32; /* board ID */
- err = SReadWord(&mySpBlock);
- if (err) { /* report error */
- continue;
- }
- theBoardID = (mySpBlock.spResult & 0x0000FFFF);
-
- if (theBoardID == kTobyBoardID)
- return true;
- }
- return false;
- }